package com.demo.phonerepair.controller;

import com.demo.phonerepair.module.RepairQueryModule;
import com.demo.phonerepair.pojo.Repair;
import com.demo.phonerepair.pojo.User;
import com.demo.phonerepair.service.RepairService;
import com.demo.phonerepair.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;

    @RequestMapping("/getAllRepair")
    public Result<Map<String, Object>> getAllRepair(RepairQueryModule repairQueryModule) {
        return repairService.getRepairListByCondition(repairQueryModule);
    }

    // 添加获取接待人员列表的接口
    @RequestMapping("/getAllReceptionist")
    public Result<List<User>> getAllReceptionist() {
        List<User> receptionists = repairService.getAllReceptionist();
        return Result.success(receptionists);
    }

    @PostMapping("/createRepair")
    public Result<String> createRepair(@RequestBody Repair repair) {
        boolean isCreated = repairService.createRepair(repair);
        if (isCreated) {
            return Result.success("创建成功");
        } else {
            return Result.fail("创建失败",500);
        }
    }
    @PostMapping("/deleteRepair")
    public Result<String> deleteRepair (@RequestParam("repairId") Integer repairId,
                                        @RequestParam("userId") Integer userId,
                                        @RequestParam("password") String password){
        boolean isDeleted = repairService.deleteRepair(repairId,userId,password);
        if (isDeleted) {
            return Result.success("删除成功");
        }
        return Result.fail("删除失败",500);

    }
}
